package edu.indiana.d2i.job;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import edu.indiana.d2i.job.HTRCJobStatus.STATUS;
import edu.indiana.d2i.vm.VMInfo;
import edu.indiana.d2i.vm.VMPoolManager;

public class JobFIFOSchedule implements JobSchedule {

	@Override
	public HTRCJobInProgress schedule(Map<String, HTRCJobInProgress> jobqueue,
			VMPoolManager resource) {
		Iterator<Entry<String, HTRCJobInProgress>> iterator = jobqueue.entrySet().iterator();
		Entry<String, HTRCJobInProgress> entry = iterator.next();
		VMInfo[] vms = resource.requestVMs(entry.getValue().jobConf);
		if (vms != null) {
			entry.getValue().jobStatus.status = STATUS.RUNNING;
			return new HTRCJobInProgress(entry.getValue().jobConf, entry.getValue().jobStatus, vms);
		}
		return null;
	}
}
